package ch.zbw.sysVentory.agent.readData;
import java.io.*;



public class CmdLesen {
    
    public static String lesen(String befehl){
	try {
		//Mit Runtime.getRuntime().exec(befehl) externe Befehle aufrufen
	    Process process = Runtime.getRuntime().exec(befehl);
	    StreamReader reader = new StreamReader(process.getInputStream());
	    reader.start();
	    process.waitFor();
	    reader.join();
	    String result = reader.getResult();
	    return result;
	    

	} catch ( Exception e) {
	    
	    e.printStackTrace();
	}
	return null;
    }
    
    static class StreamReader extends Thread {
	    private InputStream is;
	    private StringWriter sw;

	    StreamReader(InputStream is) {
	      this.is = is;
	      sw = new StringWriter();
	    }

	    public void run() {
	      try {
	        int c;
	        while ((c = is.read()) != -1)
	          sw.write(c);
	        }
	        catch (IOException e) { ; }
	      }

	    String getResult() {
	      return sw.toString();
	    }
	  }
    
}
